﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CCF20Model.ConfigurationFile
{
    public class MembershipConnection : IConfiguration
    {
        private string zicMonitorConnectionTemplate = "Data Source={0};Initial Catalog={1};User Id={2};Password={3};";

        private IConfiguration _previousConfig;
        private string strResult = string.Empty;

        public MembershipConnection(IConfiguration previousConfig)
        {
            _previousConfig = previousConfig;
        }

        public string VerifyResult()
        {
            WiseLinkConfiguration myConfig = ConfiguraitonHelper.MyConfiguration;
            string myConfigConnection = string.Format(zicMonitorConnectionTemplate, myConfig.database, myConfig.catalog, myConfig.user, myConfig.password);

            string membershipConnection = ConfiguraitonHelper.GetConfigValueFromAppConfig(AppConfigFileName.CCF, AppConfigFileNodeName.AspnetMembershipConnectionString);

            if (!membershipConnection.Equals(myConfigConnection, StringComparison.OrdinalIgnoreCase))
            {
                ConfiguraitonHelper.SetConfigValueToAppConfig(AppConfigFileName.CCF, AppConfigFileNodeName.AspnetMembershipConnectionString, myConfigConnection);
                strResult = string.Format("CCF20 AppConfig File AspnetMembershipConnectionString has different value than the config.xml\r\n{0}\r\n{1}", membershipConnection, myConfigConnection);
            }
         
            return string.Format("{0} \r\n{1}", _previousConfig.VerifyResult(), strResult);
        }

    }
}
